package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursePlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理模块相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理模块-分页查询
     */

    @GetMapping
    @ApiOperation(value = "分页查询")
    public ResponseResult<PageResponse> findByPage(
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingProjectVo> page = nursingProjectService.findByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(page);
    }

    /**
     * 护理模块-新增
     */

    @PostMapping
    public ResponseResult addProject(@RequestBody NursingProject nursingProject) {
        nursingProjectService.addProject(nursingProject);
        return ResponseResult.success();
    }

    /**
     * 护理模块-根据id查询护理
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> selectProjectById(@PathVariable(name = "id")Integer id){
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 护理模块-编辑
     */
    @PutMapping
    public ResponseResult editProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateProject(nursingProject);
        return ResponseResult.success();
    }

    /**
     * 护理模块-启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult choiceProject(@PathVariable(name = "id") Integer id,
                                        @PathVariable(name = "status") Integer status){
        nursingProjectService.choiceProject(id,status);
        return ResponseResult.success();
    }

    /**
     * 护理模块-删除
     */
    @DeleteMapping("/{id}")
    public ResponseResult delectProject(@PathVariable(name = "id") Integer id){
        nursingProjectService.deleteProject(id);
        return ResponseResult.success();
    }

    /**
     * 护理模块-查询所有
     */
    @GetMapping("/all")
    public ResponseResult<NursingProjectVo> selectAll(){
        List<NursingProjectVo> list = nursingProjectService.selectAll();
        return success(list);
    }
}
